import math

class matrix:
    val = []
    shape = (0,)

    def __init__(self, val):
        if type(val) == list:
            self.val = val
        if type(val) == matrix:
            self.val = val.val
        self.update_shape()

    def update_shape(self):
        self.shape = (len(self.val),)
        if len(self.val) > 0 and type(self.val[0]) == list:
            self.shape += (len(self.val[0]),)

    def size(self):
        return self.shape

    def row(self, r, normal=False):
        if len(self.shape) == 1:
            return self.val
        if not normal:
            return self.val[r - 1]
        else:
            return self.val[r]

    def col(self, c, normal=False):
        if len(self.shape) == 1:
            return self.val
        else:
            if not normal:
                return [self.val[i][c - 1] for i in range(self.shape[0])]
            else:
                return [self.val[i][c] for i in range(self.shape[0])]

    def create_matrix(shape):
        result = []
        r,c=shape
        for _ in range(r):
            result.append([0 for _ in range(c)])
        return matrix(result)

    def operator(self, vector_operator, mat_operator, other, result):
        for i in range(result.shape[0]):
            for j in range(result.shape[1]):
                if type(other) == int or type(other) == float:
                    result.val[i][j] = vector_operator(result.val[i][j], other)
                else:
                    result.val[i][j] = mat_operator(i, j)
        return result

    def add(self, other):
        def matadd(i, j):
            return self.val[i][j] + other.val[i][j]
        return self.operator((lambda a, b: a + b), matadd, other, matrix(self.val))

    def dot(vector1, vector2):
        v1 = vector1
        v2 = vector2
        if type(vector1) == matrix:
            v1 = vector1.val
        if type(vector2) == matrix:
            v2 = vector2.val
        if type(v1) == int or type(v1) == float:
            return v1 * v2

        result = 0
        for i in range(len(v1)):
            result += v1[i] * v2[i]
        return result

    def mul(self, other):
        def matmul(i, j):
            return matrix.dot(self.row(i,True), other.col(j,True))

        return self.operator((lambda a, b: a * b), matmul, other,
                             matrix.create_matrix((self.shape[0],other.shape[1])))

    def relu(self):
        newMat=matrix(self)
        for i in range(self.shape[0]):
            for j in range(self.shape[1]):
                newMat.val[i][j] = max(0,self.val[i][j])
        return newMat

    def exp(self):
        newMat=matrix(self)
        for i in range(self.shape[0]):
            for j in range(self.shape[1]):
                newMat.val[i][j] = math.exp(self.val[i][j])
        return newMat

    def sum(self):
        r=0
        for i in range(self.shape[0]):
            for j in range(self.shape[1]):
                r+=self.val[i][j]
        return r

    def max(self):
        r = None
        for i in range(self.shape[0]):
            for j in range(self.shape[1]):
                if r is None:
                    r=self.val[i][j]
                elif r<self.val[i][j]:
                    r=self.val[i][j]
        return r

    def softmax(self):
        x=self-self.max()
        return x.exp()/x.sum()

    def __add__(self, other):
        newMat=matrix(self)
        return newMat.add(other)

    def __mul__(self, other):
        return self.mul(other)

    def __sub__(self, other):
        return self.add(-1 * other)

    def __truediv__(self, other):
        newMat = matrix(self)
        for i in range(self.shape[0]):
            for j in range(self.shape[1]):
                newMat.val[i][j] /= other
        return newMat

    def transpose(self):
        if len(self.size()) == 1:
            return matrix(self.val)
        else:
            result = matrix([self.col(i + 1) for i in range(self.shape[1])])
            return result

    def __str__(self):
        return str(self.val)

    def __repr__(self):
        return self.__str__()

NM=list(map(int, input().split()))
n=NM[0]
m=NM[1]
X = list(map(int, input().split()))
W1 = list(map(float, input().split()))
W2 = list(map(float, input().split()))

def getMat(W,m,n):
    i=0
    rList=[]
    while (i+n)<=len(W):
        rList.append(W[i:i+n])
        i+=n
    return matrix(rList)

X=matrix([X])
X=X.transpose()
W1=getMat(W1,m,n)
W2=getMat(W2,10,m)

def calcu(X):
    A=W1.mul(X)
    Z=W2.mul(A.relu())
    return Z.softmax().val

def getMaxSub(l):
    return l.index(max(l))

result=calcu(X)
resultClass=getMaxSub(result)

maxOther=0
minSelf=result[resultClass][0]
oldSelf=result[resultClass][0]

def test(X):
    global maxOther
    global minSelf
    newResult=calcu(X)
    newResultClass=getMaxSub(newResult)
    if newResultClass!=resultClass:
        otherProb=newResult[newResultClass][0]
        if otherProb>maxOther:
            maxOther=otherProb
            return True
    else:
        if maxOther==0:
            selfProb=newResult[resultClass][0]
            if selfProb<minSelf:
                minSelf=selfProb
                return True
    return False

bestSub=None
bestVal=None

def search(X,sub,start,end):
    global bestSub
    global bestVal
    oldVal=X.val[sub][0]
    for i in range(start,end):
        if i!=oldVal:
            X.val[sub][0]=i
            if test(X):
                bestSub=sub
                bestVal=i
    X.val[sub][0]=oldVal

def fastTest(X,sub):
    oldVal = X.val[sub][0]

    def test(X):
        newResult = calcu(X)
        newResultClass = getMaxSub(newResult)
        '''
        if newResultClass != resultClass:
            return newResult[newResultClass][0]
        else:
            return (newResult[newResultClass][0])/
        '''
        return math.fabs(newResult[resultClass][0]-oldSelf)

    bestI=-1
    bestr=0
    i=4
    while i+4<128:
        X.val[sub][0] = i
        r=test(X)/math.fabs(X.val[sub][0]-oldVal)
        if r>bestr:
            bestI=i
            bestr=r
            print(sub,i,r)
        i+=8

    X.val[sub][0] = oldVal
    return bestI-4

length,_=X.shape
for i in range(length):
    start = fastTest(X, i)
    search(X, i, start, start + 8)

print(bestSub+1,bestVal)